Skip to content

fix: MiMo ASR API Key 为空竞态修复#632

Merged
H-Chris233 merged 1 commit into
Open-Less:betafrom
H-Chris233:fix/mimo-asr-api-key-race
Jun 9, 2026
Merged

fix: MiMo ASR API Key 为空竞态修复#632
H-Chris233 merged 1 commit into
Open-Less:betafrom
H-Chris233:fix/mimo-asr-api-key-race

Conversation

@H-Chris233

@H-Chris233 H-Chris233 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

User description

问题

小米 MiMo ASR 在填写完所有信息后,「测试连接」或开始听写时提示 API Key 为空

根因

三个环节的竞态条件叠加:

1. 前端 onBlur 与 validate 按钮的 IPC 竞态

`CredentialField.onBlur` 触发 `save()`(async)但未 `await`。用户输入 Key 失焦后立即点「测试连接」时,`validateProviderCredentials` 的 IPC 可能在 `setCredential` IPC 完成前到达后端,读到空的凭据缓存。

2. 组件卸载后 stale save 未取消

`CredentialField` 通过 `key` prop 在 provider 切换时强制 remount,但飞行中的 debounce save 没有挂载守卫。旧组件的 `setCredential` IPC 可能在 `active.asr` 已切换后才到达后端,把空值写入新 provider。

3. 后端 read_mimo_credentials 静默吞错

`CredentialsVault::get().ok().flatten().unwrap_or_default()` 链将 keyring 读取错误静默转成空串,外部完全感知不到。

修复

文件 改动
`ProvidersSection.tsx` 新增 `mountedRef` 守卫;`save()` 中双重挂载检查;`onBlur` 改为 `void save()`
`llm_pipeline.rs` `read_mimo_credentials` 改为显式 match:`Ok(None)` → warn、`Err` → error

验证

  • `cargo check` 编译通过
  • `cargo test` 480 tests 全部通过(含 6 个 MiMo 专项测试)

PR Type

Bug fix


Description

  • Add mountedRef guards to prevent stale saves after unmount

  • Change onBlur to void save() to avoid race with validate IPC

  • Improve error logging in read_mimo_credentials instead of silent defaults


Diagram Walkthrough

flowchart LR
  A[CredentialField onBlur] --> B[setCredential IPC]
  B --> C[Backend credential cache]
  D[Test Connection] --> E[validateProviderCredentials IPC]
  E --> C
  C -->|race: empty cache| F[API Key empty]
  G[mountedRef guard] -.->|prevents stale save| B
  H[explicit match in read_mimo_credentials] -.->|logs errors| C
Loading

File Walkthrough

Relevant files
Bug fix
llm_pipeline.rs
Improve error handling in read_mimo_credentials                   

openless-all/app/src-tauri/src/coordinator/llm_pipeline.rs

  • Replaced silent .ok().flatten().unwrap_or_default() with explicit
    match for credential retrieval
  • Added warn log when credential is empty and error log when keyring
    fails
+11/-4   
ProvidersSection.tsx
Add mount guard and fix onBlur race condition                       

openless-all/app/src/pages/settings/ProvidersSection.tsx

  • Added mountedRef useRef to guard against async save after component
    unmount
  • Changed onBlur to void save() to prevent unhandled promise and IPC
    race with validate
+7/-1     

1. CredentialField onBlur: save() fire-and-forget 与 validate 按钮存在 IPC 竞态
   — 用户输入 Key 后立即点「测试连接」时 setCredential 可能晚于 validate 到达后端。
   — 添加 mountedRef 守卫防止组件卸载后 stale save。

2. read_mimo_credentials: 将 .ok().flatten().unwrap_or_default() 改为显式 match
   — keyring 读取失败不再静默吞错,分别用 warn/error 记日志。
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@H-Chris233 H-Chris233 merged commit 6385493 into Open-Less:beta Jun 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant